<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/dute_favicon_32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/dute_favicon_16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="google-site-verification" content="mpI5dkydstZXl6UcDCppqktXK0bbvqdZ6LkZ3KNk4Iw">
  <meta name="baidu-site-verification" content="code-a1LksZX2Ds">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"whitestore.top","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="关于redis持久化的一些学习了解，以及一些拓展知识的了解">
<meta property="og:type" content="article">
<meta property="og:title" content="redis学习 - redis 持久化">
<meta property="og:url" content="https://whitestore.top/2020/11/21/redis-chijiu/index.html">
<meta property="og:site_name" content="爱看书的阿东">
<meta property="og:description" content="关于redis持久化的一些学习了解，以及一些拓展知识的了解">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-11-21T14:24:47.000Z">
<meta property="article:modified_time" content="2023-07-16T06:28:09.231Z">
<meta property="article:author" content="阿东">
<meta property="article:tag" content="Redis">
<meta property="article:tag" content="持久化">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://whitestore.top/2020/11/21/redis-chijiu/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>redis学习 - redis 持久化 | 爱看书的阿东</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="爱看书的阿东" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">爱看书的阿东</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">赐他一块白色石头，石头上写着新名</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://whitestore.top/2020/11/21/redis-chijiu/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="阿东">
      <meta itemprop="description" content="随遇而安">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱看书的阿东">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          redis学习 - redis 持久化
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-11-21 22:24:47" itemprop="dateCreated datePublished" datetime="2020-11-21T22:24:47+08:00">2020-11-21</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-07-16 14:28:09" itemprop="dateModified" datetime="2023-07-16T14:28:09+08:00">2023-07-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Redis/" itemprop="url" rel="index"><span itemprop="name">Redis</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/11/21/redis-chijiu/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/11/21/redis-chijiu/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>
            <div class="post-description">关于redis持久化的一些学习了解，以及一些拓展知识的了解</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>无论面试和工作，持久化都是重点。</p>
<p>一般情况下,redis占用内存超过20GB以上的时候，必须考虑主从多redis实例进行数据同步和备份保证可用性。</p>
<p>rbd保存的文件都是 <code>dump.rdb</code>，都是配置文件当中的快照配置进行生成的。一般业务情况只需要用rdb即可。</p>
<p>aof默认是不开启的，因为aof非常容易产生大文件，虽然官方提供重写但是在文件体积过大的时候还是容易造成阻塞，谨慎考虑使用</p>
<p>rbd和aof在大数据量分别有各种不同情况的系统性能影响，具体使用何种解决策略需要根据系统资源以及业务的实际情况决定。</p>
<a id="more"></a>

<h2 id="数据设计影响持久化："><a href="#数据设计影响持久化：" class="headerlink" title="数据设计影响持久化："></a>数据设计影响持久化：</h2><p><span class="exturl" data-url="aHR0cHM6Ly9zenRoYW5hdG9zLmdpdGh1Yi5pby90b3BpYy9yZWRpcy9pbXByb3ZlLTAxLw==" title="https://szthanatos.github.io/topic/redis/improve-01/">https://szthanatos.github.io/topic/redis/improve-01/<i class="fa fa-external-link"></i></span></p>
<h2 id="为什么要持久化？"><a href="#为什么要持久化？" class="headerlink" title="为什么要持久化？"></a>为什么要持久化？</h2><ol>
<li>重用数据</li>
<li>防止系统故障备份重要数据</li>
</ol>
<h3 id="持久化的方式"><a href="#持久化的方式" class="headerlink" title="持久化的方式"></a>持久化的方式</h3><ol>
<li>RDB 快照：将某一个时刻的所有数据写入到磁盘</li>
<li>AOF（append-only file）：将所有的命令写入到此判断。</li>
</ol>
<p>默认情况：<strong>RDB</strong>，AOF需要手动开启</p>
<h2 id="redis-conf持久化配置说明"><a href="#redis-conf持久化配置说明" class="headerlink" title="redis.conf持久化配置说明"></a>redis.conf持久化配置说明</h2><p>在<code>redis.conf</code>文件当中，存在如下的选项：</p>
<p><code>redis.conf</code>当中RDB的相关配置</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#是否开启rdb压缩 默认开启</span></span><br><span class="line"><span class="attr">rdbcompression</span> <span class="string">yes</span></span><br><span class="line"><span class="comment">#代表900秒内有一次写入操作，就记录到rdb</span></span><br><span class="line"><span class="attr">save</span> <span class="string">900 1</span></span><br><span class="line"><span class="comment"># rdb的备份文件名称</span></span><br><span class="line"><span class="attr">dbfilename</span> <span class="string">dump.rdb</span></span><br><span class="line"><span class="comment"># 表示备份文件存放位置</span></span><br><span class="line"><span class="attr">dir</span> <span class="string">./</span></span><br></pre></td></tr></table></figure>

<p><code>redis.conf</code>当中AOF的相关配置</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 是否开启aof，默认是关闭的</span></span><br><span class="line"><span class="attr">appendonly</span> <span class="string">no</span></span><br><span class="line"><span class="comment">#aof的文件名称</span></span><br><span class="line"><span class="attr">appendfilename</span> <span class="string">"appendonly.aof"</span></span><br><span class="line"><span class="comment"># no: don't fsync, just let the OS flush the data when it wants. Faster.</span></span><br><span class="line"><span class="comment"># always: fsync after every write to the append only log. Slow, Safest.</span></span><br><span class="line"><span class="comment"># everysec: fsync only one time every second. Compromise.</span></span><br><span class="line"><span class="attr">appendfsync</span> <span class="string">everysec</span></span><br><span class="line"><span class="comment"># 在进行rewrite的时候不开启fsync，即不写入缓冲区，直接写入磁盘，这样会造成IO阻塞，但是最为安全，如果为yes表示写入缓冲区，写入的适合redis宕机会造成数据持久化问题(在linux的操作系统的默认设置下，最多会丢失30s的数据)</span></span><br><span class="line"><span class="meta">no-appendfsync-on-rewrite</span> <span class="string">no</span></span><br><span class="line"><span class="comment"># 下面两个参数要配合使用，代表当redis内容大于64m同时扩容超过100%的时候会执行bgrewrite，进行持久化</span></span><br><span class="line"><span class="meta">auto-aof-rewrite-percentage</span> <span class="string">100</span></span><br><span class="line"><span class="meta">auto-aof-rewrite-min-size</span> <span class="string">64mb</span></span><br></pre></td></tr></table></figure>

<h2 id="RDB"><a href="#RDB" class="headerlink" title="RDB"></a>RDB</h2><h3 id="创建rdb快照的几种方式："><a href="#创建rdb快照的几种方式：" class="headerlink" title="创建rdb快照的几种方式："></a>创建rdb快照的几种方式：</h3><ol>
<li>客户端向redis发送bgsave的命令（注意windows不支持bgsave），此时reids调用 <strong>fork</strong> 创建子进程，父进程继续处理，子进程将快照写入磁盘，父进程继续处理请求。</li>
<li>客户端发送save命令创建快照。注意这种方式会<strong>阻塞</strong>整个父进程。很少使用，特殊情况才使用。</li>
<li>redis通过shutdown命令关闭服务器请求的时候，此时redis会停下所有工作执行一次save，阻塞所有客户端不再执行任何命令并且进行磁盘写入，写入完成关闭服务器。</li>
<li>redis集群的时候，会发送sync 命令进行一次复制操作，如果主服务器<strong>没有执行</strong>或者<strong>刚刚执行完</strong>bgsave，则会进行bgsave。</li>
<li>执行<strong>flushall</strong> 命令</li>
</ol>
<h3 id="RDB快照的一些注意点"><a href="#RDB快照的一些注意点" class="headerlink" title="RDB快照的一些注意点:"></a>RDB快照的一些注意点:</h3><ol>
<li><strong>只使用rdb的时候</strong>，如果创建快照的时候redis崩溃，redis会留存上一次备份快照，但是具体丢失多少数据由备份时间查看</li>
<li>只适用一些可以容忍一定数据丢失的系统，否则需要考虑aof持久化</li>
<li>在大数据量的场景下，特别是内存达到20GB以上的适合，一次同步大约要4-6秒<ol>
<li>一种方式是用手动同步，在凌晨的适合进行手动阻塞同步，比BGSAVE快一些</li>
</ol>
</li>
</ol>
<blockquote>
<p>一种解决方法：</p>
<p>通过日志记录来恢复中断的日志，来进行数据的恢复</p>
</blockquote>
<p>如何通过修改配置来获得想要的持久化？</p>
<ol>
<li>修改save参数，尽量在开发环境模拟线上环境设置save，过于频繁造成资源浪费，过于稀少有可能丢失大量数据</li>
<li>日志进行聚合计算，按照save进行计算最多会丢失多少时间的数据，判断容忍性，比如一小时可以设置 <code>save 3600 1</code></li>
</ol>
<h3 id="RDB的优缺点对比："><a href="#RDB的优缺点对比：" class="headerlink" title="RDB的优缺点对比："></a>RDB的优缺点对比：</h3><h4 id="优点："><a href="#优点：" class="headerlink" title="优点："></a>优点：</h4><ol>
<li>适合大规模的数据恢复</li>
<li>如果数据不小心误删，可以及时恢复</li>
<li>恢复速度一般情况下快于aof</li>
</ol>
<h4 id="缺点："><a href="#缺点：" class="headerlink" title="缺点："></a>缺点：</h4><ol>
<li>需要一定的时间间隔，如果redis意外宕机，最后一次修改的数据就没有了，具体丢失多少数据需要看持久化策略</li>
<li>fork进程的时候，会占用一定的内存空间，如果fork的内存过于庞大，可能导致秒级别的恢复时间</li>
<li>数据文件经过redis压缩，可读性较差</li>
</ol>
<h2 id="AOF（append-only-fail）"><a href="#AOF（append-only-fail）" class="headerlink" title="AOF（append only fail）"></a>AOF（append only fail）</h2><p>其实就是把我们的命令一条条记录下来，类似linux的<code>history</code></p>
<p>默认是不开启的，需要手动开启，开启之后需要重启</p>
<p>如果aof文件错位了，可以用<code>redis-check-aof</code> 进行文件修复</p>
<blockquote>
<p>文件同步：写入文件的时候，会发生三件事：</p>
<ol>
<li>file.write() 方法将文件存储到缓冲区</li>
<li>file.flush() 将缓冲区的内容写入到硬盘</li>
<li>sync 文件同步，阻塞直到写入硬盘为止</li>
</ol>
</blockquote>
<h3 id="AOC的同步策略"><a href="#AOC的同步策略" class="headerlink" title="AOC的同步策略"></a>AOC的同步策略</h3><table>
<thead>
<tr>
<th>选项</th>
<th>同步频率</th>
</tr>
</thead>
<tbody><tr>
<td>always</td>
<td>每次命令都写入磁盘，严重降低redis速度</td>
</tr>
<tr>
<td>everysec</td>
<td>每秒执行一次，显示将多个命令写入到磁盘</td>
</tr>
<tr>
<td>no</td>
<td>操作系统决定，佛系</td>
</tr>
</tbody></table>
<p>分析：</p>
<ol>
<li>第一种对于固态的硬盘的伤害比较大，我们都知道固态的擦写次数的寿命是远远小于机械硬盘的，频繁的io是容易对固态造成欺骗认为一次擦写，导致本就寿命不长的固态变得更命短，<strong>基本不用</strong>，特殊情况下有可能用得到</li>
<li>第二种是默认的方式，也是推荐以及比较实用的方式，最多只会丢失一秒的数据，这种方式比较好的保证数据的备份可用，<strong>推荐使用</strong></li>
<li>第三种对于CPU的压力是最小的，因为由系统决定，但是需要考虑能不能接受不定量的数据丢失，还有一个原因是硬盘将缓冲区刷新到硬盘不定时，所以<strong>不建议使用</strong></li>
</ol>
<h3 id="重写和压缩AOF文件："><a href="#重写和压缩AOF文件：" class="headerlink" title="重写和压缩AOF文件："></a>重写和压缩AOF文件：</h3><p>由于1秒一次同步在不断写入之后造成文件内容越来越大，同时同步速度也会变慢，为了解决这个问题，redis引入了<code>bgrewriteaof</code>命令来进行压缩，和<code>bgsave</code>创建快照类似，同样会有子进程拖垮的问题，同时会有大文件在重写的时候带来巨大的文件系统删除的压力，导致系统阻塞。</p>
<p>命令如下</p>
<p><code>bgrewriteaof</code></p>
<p>示例如下：</p>
<blockquote>
<p>127.0.0.1:16379&gt; BGREWRITEAOF<br>Background append only file rewriting started</p>
</blockquote>
<blockquote>
<p>参数控制：</p>
<p>auto-aof-rewrite-percentage：<strong>100</strong></p>
<p>auto-aof-rewrite-min-size ：<strong>64MB</strong></p>
<p>这里案例配置代表当AOF大于64并且扩大了100%将处罚<strong>bgrewrite</strong>命令</p>
</blockquote>
<h4 id="redis-aof的rewrite做了那些事？"><a href="#redis-aof的rewrite做了那些事？" class="headerlink" title="redis aof的rewrite做了那些事？"></a>redis aof的rewrite做了那些事？</h4><ol>
<li>对于一些冗余的命令进行清除</li>
<li>检测存在错误的命令，将错误命令下面的所有命令都进行清理，一般情况是末尾由于宕机没有执行完的一些命令清理。</li>
</ol>
<h3 id="aof的优缺点对比"><a href="#aof的优缺点对比" class="headerlink" title="aof的优缺点对比"></a>aof的优缺点对比</h3><h4 id="优点：-1"><a href="#优点：-1" class="headerlink" title="优点："></a>优点：</h4><ol>
<li>从不同步，效率高</li>
<li>每秒同步一次，可能丢失一秒数据</li>
<li>每次修改都同步，文件完整性好</li>
</ol>
<h4 id="缺点：-1"><a href="#缺点：-1" class="headerlink" title="缺点："></a>缺点：</h4><ol>
<li>相对于数据文件来说，aof远远大于rdb。修复速度慢一些</li>
<li>存在未知的bug，比如如果重写aof文件的时候突然中断，会有很多奇怪的现象</li>
</ol>
<h2 id="如何检查redis的性能瓶颈："><a href="#如何检查redis的性能瓶颈：" class="headerlink" title="如何检查redis的性能瓶颈："></a>如何检查redis的性能瓶颈：</h2><ol>
<li>redis-benchmark 官方推荐的性能测试工具，非常强大，具体的地址为：<span class="exturl" data-url="aHR0cHM6Ly93d3cucnVub29iLmNvbS9yZWRpcy9yZWRpcy1iZW5jaG1hcmtzLmh0bWw=" title="https://www.runoob.com/redis/redis-benchmarks.html">https://www.runoob.com/redis/redis-benchmarks.html<i class="fa fa-external-link"></i></span></li>
<li>Redis-cli中调用<code>slowlog get</code>，作用是返回执行时间<strong>超过redis.conf</strong>中定义的持续时间的命令列表，注意这个时间仅仅是请求的处理时间，不包含网络通信的时间，<strong>默认值是一秒</strong>，</li>
</ol>
<blockquote>
<p>redis.conf 当中对于慢日志的解释:</p>
<p>The following time is expressed in microseconds, so 1000000 is equivalent to one second. Note that a negative number disables the slow log, while a value of zero forces the logging of every command.</p>
<p>接下来的时间以微秒为单位，因此1000000等于一秒。 请注意，负数将禁用慢速日志记录，而零值将强制记录每个命令。<strong>（以微秒为单位）</strong></p>
<p><strong>slowlog-log-slower-than 10000</strong></p>
<p>There is no limit to this length. Just be aware that it will consume memory. You can reclaim memory used by the slow log with SLOWLOG RESET.</p>
<p>该长度没有限制。 请注意，它将消耗内存。 您可以使用SLOWLOG RESET回收慢速日志使用的内存。<strong>（意思就是说超过128条之后的命令会被自动移除）</strong></p>
<p><strong>slowlog-max-len 128</strong></p>
</blockquote>
<blockquote>
<p>可以用命令 SLOWLOG RESET 清楚慢日志占用的内存</p>
<p>127.0.0.1:16379&gt; SLOWLOG reset<br>OK</p>
</blockquote>
<p>==慢日志是存储在内存当中的，切记==</p>
<h2 id="持久化性能建议"><a href="#持久化性能建议" class="headerlink" title="持久化性能建议"></a>持久化性能建议</h2><blockquote>
<ul>
<li>因为RDB文件只用作后备用途，建议只在Slave上持久化RDB文件，而且只要15分钟备份一次就够了，只保留save 900 1这条规则。</li>
</ul>
</blockquote>
<blockquote>
<ul>
<li>如果Enalbe AOF，好处是在最恶劣情况下也只会丢失不超过两秒数据，启动脚本较简单只load自己的AOF文件就可以了。代价一是带来了持续的IO，二是AOF rewrite的最后将rewrite过程中产生的新数据写到新文件造成的阻塞几乎是不可避免的。只要硬盘许可，应该尽量减少AOF rewrite的频率，AOF重写的基础大小默认值64M太小了，可以设到5G以上。默认超过原大小100%大小时重写可以改到适当的数值。</li>
</ul>
</blockquote>
<blockquote>
<ul>
<li>如果不Enable AOF ，仅靠Master-Slave Replication 实现高可用性也可以。能省掉一大笔IO也减少了rewrite时带来的系统波动。代价是如果Master/Slave同时倒掉，会丢失十几分钟的数据，启动脚本也要比较两个Master/Slave中的RDB文件，载入较新的那个。<strong>新浪微博</strong>就选用了这种架构。</li>
</ul>
</blockquote>
<p>其他性能优化指南（强烈推荐）：</p>
<p><span class="exturl" data-url="aHR0cHM6Ly9zenRoYW5hdG9zLmdpdGh1Yi5pby90b3BpYy9yZWRpcy9pbXByb3ZlLTAyLw==" title="https://szthanatos.github.io/topic/redis/improve-02/">https://szthanatos.github.io/topic/redis/improve-02/<i class="fa fa-external-link"></i></span></p>
<h2 id="总结对比rdb和aof："><a href="#总结对比rdb和aof：" class="headerlink" title="总结对比rdb和aof："></a>总结对比rdb和aof：</h2><table>
<thead>
<tr>
<th></th>
<th>RDB</th>
<th>AOF</th>
</tr>
</thead>
<tbody><tr>
<td><strong>存储内容</strong></td>
<td>数据</td>
<td>写操作日志</td>
</tr>
<tr>
<td><strong>性能影响</strong></td>
<td>小</td>
<td>大</td>
</tr>
<tr>
<td><strong>恢复速度</strong></td>
<td>高</td>
<td>低</td>
</tr>
<tr>
<td><strong>存储空间</strong></td>
<td>小</td>
<td>大</td>
</tr>
<tr>
<td><strong>可读性</strong></td>
<td>低</td>
<td>高</td>
</tr>
<tr>
<td><strong>安全程度</strong></td>
<td>较低，保存频率低</td>
<td>较高，保存频率高</td>
</tr>
<tr>
<td><strong>默认开启</strong></td>
<td>是</td>
<td>否</td>
</tr>
<tr>
<td><strong>存储策略</strong></td>
<td><code>save 900 1</code>：九百秒内一次修改即保存 <code>save 300 10</code>：三百秒内十次修改即保存 <code>save 60 10000</code>：六十秒内一万次修改即保存 允许自定义</td>
<td><code>always</code>：逐条保存 or <code>everysec</code>：每秒保存 or <code>no</code>：系统自己决定什么时候保存</td>
</tr>
</tbody></table>
<h2 id="其他拓展知识："><a href="#其他拓展知识：" class="headerlink" title="其他拓展知识："></a>其他拓展知识：</h2><h3 id="关于linux内核开启transparent-hugepage会带来的阻塞问题："><a href="#关于linux内核开启transparent-hugepage会带来的阻塞问题：" class="headerlink" title="关于linux内核开启transparent_hugepage会带来的阻塞问题："></a>关于linux内核开启<code>transparent_hugepage</code>会带来的阻塞问题：</h3><p>个人对于Linux学艺不精，就直接引用文章了，侵权请联系删除</p>
<p><span class="exturl" data-url="aHR0cHM6Ly93d3cuY25ibG9ncy5jb20va2Vycnljb2RlL3AvNDY3MDkzMS5odG1s" title="https://www.cnblogs.com/kerrycode/p/4670931.html">Linux 关于Transparent Hugepages的介绍<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly9ibG9nLjUxY3RvLmNvbS8xMTUyMzEzLzE3Njc5Mjc=" title="https://blog.51cto.com/1152313/1767927">简单说说THP——记一次数据库服务器阻塞的问题解决<i class="fa fa-external-link"></i></span></p>
<h3 id="官方解决aof和rdb对于性能问题的折中处理方式"><a href="#官方解决aof和rdb对于性能问题的折中处理方式" class="headerlink" title="官方解决aof和rdb对于性能问题的折中处理方式"></a>官方解决aof和rdb对于性能问题的折中处理方式</h3><ol>
<li>redis4.0之后有一个参数叫做:<code>aof-use-rdb-preamble yes</code></li>
</ol>
<p>参数解释如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"># When rewriting the AOF file, Redis is able to use an RDB preamble in the</span><br><span class="line"># AOF file for faster rewrites and recoveries. When this option is turned</span><br><span class="line"># on the rewritten AOF file is composed of two different stanzas:</span><br><span class="line">#</span><br><span class="line">#   [RDB file][AOF tail]</span><br><span class="line">#</span><br><span class="line"># When loading, Redis recognizes that the AOF file starts with the &quot;REDIS&quot;</span><br><span class="line"># string and loads the prefixed RDB file, then continues loading the AOF</span><br><span class="line"># tail.</span><br><span class="line">＃重写AOF文件时，Redis可以在</span><br><span class="line">＃AOF文件可加快重写和恢复速度。 启用此选项时</span><br><span class="line">重写的AOF文件上的＃由两个不同的节组成：</span><br><span class="line">＃</span><br><span class="line">＃[RDB文件] [AOF尾巴]</span><br><span class="line">＃</span><br><span class="line">＃加载时，Redis会识别AOF文件以“ REDIS”开头</span><br><span class="line">＃字符串并加载带前缀的RDB文件，然后继续加载AOF</span><br><span class="line">＃ 尾巴。</span><br></pre></td></tr></table></figure>

<p>大致的内容就是说redis会将较早的部分内容转为RDB文件进行恢复，同时加入近期的数据为AOF文件</p>
<p>加载的时候先执行rdb文件的恢复，然后再加载aof命令</p>
<h3 id="如何进行内存清理"><a href="#如何进行内存清理" class="headerlink" title="如何进行内存清理"></a>如何进行内存清理</h3><p>在<strong>redis4.0</strong>之后，可以通过将配置里的<code>activedefrag</code>设置为<code>yes</code>开启自动清理，或者通过<code>memory purge</code>命令手动清理。</p>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>lazytime
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://whitestore.top/2020/11/21/redis-chijiu/" title="redis学习 - redis 持久化">https://whitestore.top/2020/11/21/redis-chijiu/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Redis/" rel="tag"># Redis</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/11/15/note/" rel="prev" title="记一次阿里云安装mysql （rpm安装）">
      <i class="fa fa-chevron-left"></i> 记一次阿里云安装mysql （rpm安装）
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/11/21/note/" rel="next" title="Redis学习 - Redis发布订阅">
      Redis学习 - Redis发布订阅 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#数据设计影响持久化："><span class="nav-number">1.</span> <span class="nav-text">数据设计影响持久化：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么要持久化？"><span class="nav-number">2.</span> <span class="nav-text">为什么要持久化？</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#持久化的方式"><span class="nav-number">2.1.</span> <span class="nav-text">持久化的方式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#redis-conf持久化配置说明"><span class="nav-number">3.</span> <span class="nav-text">redis.conf持久化配置说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#RDB"><span class="nav-number">4.</span> <span class="nav-text">RDB</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建rdb快照的几种方式："><span class="nav-number">4.1.</span> <span class="nav-text">创建rdb快照的几种方式：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#RDB快照的一些注意点"><span class="nav-number">4.2.</span> <span class="nav-text">RDB快照的一些注意点:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#RDB的优缺点对比："><span class="nav-number">4.3.</span> <span class="nav-text">RDB的优缺点对比：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#优点："><span class="nav-number">4.3.1.</span> <span class="nav-text">优点：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#缺点："><span class="nav-number">4.3.2.</span> <span class="nav-text">缺点：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#AOF（append-only-fail）"><span class="nav-number">5.</span> <span class="nav-text">AOF（append only fail）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#AOC的同步策略"><span class="nav-number">5.1.</span> <span class="nav-text">AOC的同步策略</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#重写和压缩AOF文件："><span class="nav-number">5.2.</span> <span class="nav-text">重写和压缩AOF文件：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#redis-aof的rewrite做了那些事？"><span class="nav-number">5.2.1.</span> <span class="nav-text">redis aof的rewrite做了那些事？</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#aof的优缺点对比"><span class="nav-number">5.3.</span> <span class="nav-text">aof的优缺点对比</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#优点：-1"><span class="nav-number">5.3.1.</span> <span class="nav-text">优点：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#缺点：-1"><span class="nav-number">5.3.2.</span> <span class="nav-text">缺点：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#如何检查redis的性能瓶颈："><span class="nav-number">6.</span> <span class="nav-text">如何检查redis的性能瓶颈：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#持久化性能建议"><span class="nav-number">7.</span> <span class="nav-text">持久化性能建议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结对比rdb和aof："><span class="nav-number">8.</span> <span class="nav-text">总结对比rdb和aof：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其他拓展知识："><span class="nav-number">9.</span> <span class="nav-text">其他拓展知识：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#关于linux内核开启transparent-hugepage会带来的阻塞问题："><span class="nav-number">9.1.</span> <span class="nav-text">关于linux内核开启transparent_hugepage会带来的阻塞问题：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#官方解决aof和rdb对于性能问题的折中处理方式"><span class="nav-number">9.2.</span> <span class="nav-text">官方解决aof和rdb对于性能问题的折中处理方式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何进行内存清理"><span class="nav-number">9.3.</span> <span class="nav-text">如何进行内存清理</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿东</p>
  <div class="site-description" itemprop="description">随遇而安</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">239</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lazyTimes"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjEwOTc0ODM1MDhAcXEuY29t" title="E-Mail → mailto:1097483508@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly93d3cuNTJwb2ppZS5jbi9ob21lLnBocD9tb2Q9c3BhY2UmdWlkPTE0OTc3MTgmZG89dGhyZWFkJnZpZXc9bWUmZnJvbT1zcGFjZQ==" title="https:&#x2F;&#x2F;www.52pojie.cn&#x2F;home.php?mod&#x3D;space&amp;uid&#x3D;1497718&amp;do&#x3D;thread&amp;view&#x3D;me&amp;from&#x3D;space">吾爱破解</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vdXNlci8yOTk5MTIzNDUyNjI2MzY2" title="https:&#x2F;&#x2F;juejin.im&#x2F;user&#x2F;2999123452626366">掘金</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3UvbGF6eXRpbWVz" title="https:&#x2F;&#x2F;segmentfault.com&#x2F;u&#x2F;lazytimes">思否</span>
        </li>
    </ul>
  </div>

      </div>

      <div class="wechat_OA">
        <span>欢迎关注我的公众号</span>
        <br>
          <!-- 这里添加你的二维码图片 -->
        <img src ="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/wechat_channel.jpg">
      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿东</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">2m</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">29:50</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'qMUpEEvBgXaMDD1b0ftgi9xr-gzGzoHsz',
      appKey     : 'UCdfT4Rfih6MO6y8DI4fstf6',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
